package com.howells.time.module.sendvideo.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;

import com.howells.time.R;
import com.howells.time.base.utils.DateUtils;
import com.howells.time.base.utils.StatusBarUtil;

import java.util.Date;

/**
 * Created by Administrator on 2016.4.18.
 */
public class SelectDateActivity extends AppCompatActivity {
    DatePicker datePicker;
    private int DayMax;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_date);
        datePicker= (DatePicker) findViewById(R.id.datePicker);
        Intent intent=getIntent();
        DayMax=intent.getIntExtra("maxday",7);
        Date date= DateUtils.str2Date(DateUtils.getCurDateStr(),"yyyy-MM-dd-HH:mm:ss");
        datePicker.setMinDate(date.getTime());
        date=DateUtils.addDay(date,DayMax);
        datePicker.setMaxDate(date.getTime());
        StatusBarUtil.setColor(this,0);
        ((TextView)findViewById(R.id.top_pannel_title)).setText("时间");
        ((TextView)findViewById(R.id.top_pannel_right)).setText("完成");
    }
    public void onClick(View view){
        switch (view.getId()){
            case R.id.top_pannel_back:
                finish();
                break;
            case R.id.top_pannel_right:
                returndata();
                finish();
                break;
        }
    }
    private void returndata(){
        int year=datePicker.getYear();
        int month=datePicker.getMonth();
        int day=datePicker.getDayOfMonth();
        System.out.println(year+""+month+""+day);
        Intent intent=getIntent();
        intent.setClass(this,SendVideoActivity.class);
        intent.putExtra("year",Integer.toString(year));
        intent.putExtra("month",Integer.toString(month+1));
        intent.putExtra("day",Integer.toString(day));
        intent.putExtra("timestamp",Long.toString(DateUtils.str2Date(year+"-"+(month+1)+"-"+day,"yyyy-MM-dd").getTime()));
        setResult(1003,intent);
    }
}
